const Router = require("koa-router")

const router = new Router()

const mongoose = require("mongoose")



@controller('api/v0/movies')
export class movieController {
    @get("/")
    @login
    @admin(['developer'])
    @log
    async getMovies(ctx, next) {
        const Movie = mongoose.model("Movie")
        const movies = await Movie.find({}).sort({
            'mate.createAt': -1
        })
        ctx.body = movies
        next()
    }
    

    @get("/:id")
    async getMovieDetail(ctx, next) {
        const Movie = mongoose.model("Movie")
        //拿到路由参数
        const id = ctx.params.id
        const movies = await Movie.findOne({ _id: id })
        ctx.body = movies
        next()
    }
}

// 把函数的执行代码放到上面的类里面
// router.get('/movies/detail/:id',async(ctx,next)=>{

// })
module.exports = router